home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / atari.trm < prev    next >
Text File  |  1993-09-15  |  10KB  |  365 lines

  1. /*
  2.  * $Id: atari.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - atari.trm */
  7. /*
  8.  * Copyright (C) 1992
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and
  13.  * that both that copyright notice and this permission notice appear
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed
  18.  * as patches to released version.
  19.  *
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  *
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   Atari Screens working with the normal VDI
  26.  *     (this should include TT and big screens)
  27.  *
  28.  * AUTHORS
  29.  *  Alexander Lehmann
  30.  *  HE Koechling
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  *
  34.  * ATARI-related comments please to alexlehm@iti.informatik.th-darmstadt.de
  35.  *
  36.  */
  37.  
  38. #ifdef __PUREC__
  39. /* why did they have to change these names ??? */
  40. #include <aes.h>
  41. #include <vdi.h>
  42. #include <tos.h>
  43. #else /* !__PUREC__ i.e. __GNUC__, maybe others */
  44. #include <aesbind.h>
  45. #include <vdibind.h>
  46. #include <osbind.h>
  47. #endif
  48.  
  49. /* default to hi-res */
  50.  
  51. #define ATARI_XMAX 640
  52. #define ATARI_YMAX 400
  53. #define ATARI_VCHAR 16
  54. #define ATARI_HCHAR 8
  55. #define ATARI_HTIC (ATARI_XMAX/100)
  56. #define ATARI_VTIC ATARI_HTIC
  57.  
  58. #define ATARI_yc(y) (ATARI_maxycoord-(y))
  59. #define ATARI_LINETYPES_MAX    11
  60. static int ATARI_linetypes[ATARI_LINETYPES_MAX] = {
  61.         0xffff, 0x1111,
  62.         0xffff, 0x5555, 0x3333, 0x7777,
  63.         0x3f3f, 0x0f0f, 0x5f5f, 0xe4e4, 0x55f5};
  64. static int ATARI_lt;
  65. static int vdi_handle=-1;
  66. static int ATARI_maxycoord;
  67. static int ATARI_rotation;
  68. static int ATARI_numcolors;
  69. static int pxy[128];            /* Maximum of 64 pixels per v_pline */
  70. static int pxy_index;
  71. static int ATARI_colors[16];
  72. static int ATARI_savecolors[16][3];
  73. static int ATARI_numpalette;
  74. #define ATARI_c_height_default 6 /* well, well ...               */
  75. static int ATARI_c_height = ATARI_c_height_default;
  76.  
  77. ATARI_options( )
  78. {
  79. #define ATARIHEXERROR "palette values 3 hex digits, please"
  80. #define ATARIHEIGHTERROR "expecting a character height"
  81.     char opt[4];
  82.     int i;
  83.     char *tok_end;
  84.  
  85.     term_options[0]='\0';
  86.     ATARI_c_height=ATARI_c_height_default;
  87.  
  88.     for( i=0 ; i<17 ; i++ ) {
  89.         if(END_OF_COMMAND) break;
  90.         if (token[c_token].length>3) {
  91.             ATARI_numpalette=0;
  92.             ATARI_c_height=ATARI_c_height_default;
  93.             term_options[0]='\0';
  94.             int_error(ATARIHEXERROR, c_token);
  95.         }
  96.  
  97.         capture( opt, c_token, c_token );
  98.         if (!i) {
  99.             ATARI_c_height = strtoul( opt, &tok_end, 10 );
  100.             if( *tok_end!='\0' ) {
  101.                 ATARI_numpalette=0;
  102.                 ATARI_c_height=ATARI_c_height_default;
  103.                 term_options[0]='\0';
  104.                 int_error(ATARIHEIGHTERROR, c_token);
  105.             }
  106.             if( ATARI_c_height>999 )
  107.                 ATARI_c_height=999;  /* avoid opt length overflow */
  108.             sprintf( opt, "%d ", ATARI_c_height );
  109.         }
  110.         else {
  111.             ATARI_colors[i-1]=strtoul( opt, &tok_end, 16 );
  112.             if( *tok_end!='\0' ) {
  113.                 ATARI_numpalette=0;
  114.                 ATARI_c_height=ATARI_c_height_default;
  115.                 term_options[0]='\0';
  116.                 int_error(ATARIHEXERROR, c_token);
  117.             }
  118.  
  119.             sprintf( opt, "%03X ", ATARI_colors[i-1] );
  120.         }
  121.         strcat( term_options, opt );
  122.         c_token++;
  123.     }
  124.     ATARI_numpalette=(i==0 ? 0 : i-1);
  125. }
  126.  
  127. ATARI_init( )
  128. {
  129.     int work_in[11];
  130.     int work_out[57];
  131.     int i;
  132.     int hchar, wchar, dummy;
  133.     int rgb[3];
  134.     int num_save;
  135.     char *colors,*tok_end;
  136.  
  137.     if( ATARI_numpalette==0 && (colors=getenv("GNUCOLORS")) && *colors ) {
  138.         for( i=0 ; i<17 ; i++ ) {
  139.             if (!i) {
  140.                 ATARI_c_height = strtoul( colors, &tok_end, 10 );
  141.                  if( colors==tok_end ) {
  142.                     i=0;
  143.                     ATARI_c_height=ATARI_c_height_default;
  144.                     break;
  145.                 }
  146.            }
  147.             else {
  148.                 if( *colors=='\0' ) break;
  149.                 ATARI_colors[i]=strtoul( colors, &tok_end, 16 );
  150.                 if( colors==tok_end || (unsigned)ATARI_colors[i]>0xfff ) {
  151.                     i=0;
  152.                     break;
  153.                 }
  154.             }
  155.             colors=tok_end;
  156.  
  157.             while( *colors==' ' ) colors++;
  158.         }
  159.         ATARI_numpalette=(i==0 ? 0 : i-1);
  160.     }
  161.  
  162.     vdi_handle=graf_handle( &wchar, &hchar, &dummy, &dummy );
  163.     if( !vdi_handle )
  164.         int_error("Fatal error opening virtual workstation", NO_CARET);
  165.  
  166.     for( i=0 ; i<10 ; work_in[i++]=1 );
  167.         work_in[10]=2;                  /* use raster coordinates */
  168.     v_opnvwk( work_in, &vdi_handle, work_out );
  169.     if( !vdi_handle )
  170.         int_error("Fatal error opening virtual workstation", NO_CARET);
  171.  
  172.     vst_height(vdi_handle, ATARI_c_height, &dummy, &dummy, &wchar, &hchar);
  173.  
  174.     vs_clip( vdi_handle, 0, work_in ); /* turn clipping off */
  175.  
  176.     term_tbl[term].xmax=work_out[0]+1;
  177.     term_tbl[term].ymax=work_out[1]+1;
  178.     term_tbl[term].h_char=wchar;
  179.     term_tbl[term].v_char=hchar;    /* hchar stands for height this time */
  180.     term_tbl[term].h_tic=(work_out[0]+1)/100;
  181.     term_tbl[term].v_tic=term_tbl[term].h_tic;
  182.  
  183.     ATARI_maxycoord=work_out[1];
  184.     ATARI_numcolors=work_out[13];
  185.     pxy_index=0;
  186.  
  187.     for( i=0 ; i<ATARI_numpalette ; i++ ) {
  188.         vq_color( vdi_handle, i, 1, ATARI_savecolors[i] );
  189.  
  190.         rgb[0]=1000*(ATARI_colors[i]>>8);
  191.         rgb[0]/=15;
  192.         rgb[1]=1000*((ATARI_colors[i]>>4)&15);
  193.         rgb[1]/=15;
  194.         rgb[2]=1000*(ATARI_colors[i]&15);
  195.         rgb[2]/=15;
  196.         vs_color(vdi_handle, i, rgb );
  197.     }
  198. #ifdef __PUREC__
  199. /* currently the PureC version runs as .prg and the GCC version runs as .ttp.
  200.    Let's hope that we soon figure out which way is the best */
  201.     v_hide_c(vdi_handle);
  202. #endif
  203. }
  204.  
  205. ATARI_reset( )
  206. {
  207.     int i;
  208.  
  209.     if( vdi_handle!=-1 ) {
  210.         for( i=0 ; i<ATARI_numpalette ; i++ ) {
  211.             vs_color(vdi_handle, i, ATARI_savecolors[i] );
  212.         }
  213. #ifdef __PUREC__
  214. /* see above */
  215.     v_show_c(vdi_handle, 0);
  216. #endif
  217.         v_clsvwk( vdi_handle );
  218.         vdi_handle=-1;
  219.     }
  220. }
  221.  
  222. ATARI_graphics( )
  223. {
  224.     int pxy[8];
  225.     MFDB mfdb;
  226.  
  227.     fflush( stdout );
  228.     fflush( stderr );
  229.     Cconws( "\033f" ); /* turn cursor off */
  230. /*  apparently v_clrwk doesn't work with overscan. We'll blit the screen clear.
  231.     v_clrwk( vdi_handle );
  232. */
  233.     mfdb.fd_addr=NULL; /* NULL means actual screen. So we don't need size etc. */
  234.  
  235.     pxy[0]=pxy[4]=0;
  236.     pxy[1]=pxy[5]=0;
  237.     pxy[2]=pxy[6]=term_tbl[term].xmax-1;
  238.     pxy[3]=pxy[7]=term_tbl[term].ymax-1;
  239.  
  240.     vro_cpyfm( vdi_handle, ALL_WHITE /*0*/, pxy, &mfdb, &mfdb );
  241.  
  242.     pxy_index=0;
  243. }
  244.  
  245. flush_line( )
  246. {
  247.     int line_type;
  248.     int color_index;
  249.     int i;
  250.  
  251.     if( pxy_index>=2 ) {
  252.         if( ATARI_numcolors==2 ) { /* Monochrome */
  253.             color_index=1;
  254.             line_type=ATARI_lt;
  255.             if (line_type >= 0)
  256.                 line_type %= (ATARI_LINETYPES_MAX - 2);
  257.         } else { /* Color */
  258.             if (ATARI_lt<0) {
  259.                 color_index=1;
  260.                 line_type= ATARI_lt;
  261.             }
  262.             else {
  263.                 color_index=2+ATARI_lt%(ATARI_numcolors-2);
  264.                 line_type=(ATARI_lt/(ATARI_numcolors-2)) % (ATARI_LINETYPES_MAX - 2);
  265.             }
  266.         }
  267.  
  268.         vswr_mode( vdi_handle, MD_TRANS);
  269.         vsl_color( vdi_handle, color_index );
  270.  
  271.         vsl_type( vdi_handle, 7 );
  272.         vsl_udsty( vdi_handle, ATARI_linetypes[line_type + 2] );
  273.  
  274.         v_pline( vdi_handle, pxy_index, pxy );
  275.     }
  276.  
  277.     if( pxy_index>=1 ) {
  278.         pxy[0]=pxy[2*(pxy_index-1)];
  279.         pxy[1]=pxy[2*(pxy_index-1)+1];
  280.         pxy_index=1;
  281.     }
  282. }
  283.  
  284. ATARI_text( )
  285. {
  286.     flush_line( );
  287.     Cnecin();        /* wait for any char --> enable screen dump */
  288.     Cconws( "\033e" );  /* turn cursor on again */
  289. }
  290.  
  291. ATARI_move( int x, int y )
  292. {
  293.     flush_line( );
  294.  
  295.     pxy_index=1;
  296.     pxy[0]=x;
  297.     pxy[1]=ATARI_yc(y);
  298. }
  299.  
  300. ATARI_vector( int x, int y )
  301. {
  302.     pxy[2*pxy_index]=x;
  303.     pxy[2*pxy_index+1]=ATARI_yc(y);
  304.     pxy_index++;
  305.  
  306.     if( pxy_index==64 ) {   /* we're all full */
  307.         flush_line( );
  308.     }
  309. }
  310.  
  311. ATARI_linetype( int lt )
  312. {
  313.     flush_line( );
  314.  
  315.     ATARI_lt=lt;
  316. }
  317.  
  318. ATARI_put_text( int x, int y, char *str )
  319. {
  320.     int vchar=term_tbl[term].v_char;
  321.     int dummy;
  322.  
  323.     if( !strlen(str) ) return;
  324.  
  325.     if( x<0 ) x=0;
  326.     if( y<0 ) y=0;
  327.  
  328.     /* align text left and to middle of char height */
  329.     vst_alignment( vdi_handle, 0, 5, &dummy, &dummy );
  330.     vst_rotation( vdi_handle, (ATARI_rotation ? 900 : 0) );
  331.     if( ATARI_rotation ) 
  332.         v_gtext( vdi_handle, x-vchar/2+1, ATARI_yc(y)-1, str );
  333.     else
  334.         v_gtext( vdi_handle, x+1, ATARI_yc(y)-vchar/2+1, str );
  335. }
  336.  
  337. TBOOLEAN ATARI_text_angle( int ang )
  338. {
  339.     ATARI_rotation=ang;
  340.  
  341.     return TRUE;
  342. }
  343.  
  344. TBOOLEAN ATARI_justify_text( int mode )
  345. {
  346.     return FALSE;
  347. }
  348.  
  349. ATARI_point( int x, int y, int number )
  350. {
  351.     int old_linetype;
  352.  
  353.     if( ATARI_numcolors==2 ) {
  354.         line_and_point( x, y, number ); /* monochrome */
  355.     } else {
  356.     /* we map colors that exceed our limit to dotted lines, but we can't do
  357.        that with the markers (sortof a generalized line_and_point) */
  358.     old_linetype=ATARI_lt;
  359.     if( ATARI_lt>ATARI_numcolors-2 )
  360.         ATARI_linetype(ATARI_lt%(ATARI_numcolors-2)); /* same color, but no dots */
  361.         do_point( x, y, number );
  362.     ATARI_linetype(old_linetype);
  363.     }
  364. }
  365.